package com.ruoyi.material.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.material.domain.VimsImageInfo;
import com.ruoyi.material.domain.vo.ImageVo;
import com.ruoyi.material.service.IVIMSFileService;
import com.ruoyi.material.service.IVimsImageInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * vims平台截图信息Controller
 * 
 * @author cyw
 * @date 2021-07-28
 */
@RestController
@RequestMapping("/material/image")
public class VimsImageInfoController extends BaseController
{
    private Logger logger = LoggerFactory.getLogger(VimsImageInfoController.class);
    @Autowired
    private IVIMSFileService vimsFileService;
    @Autowired
    private IVimsImageInfoService vimsImageInfoService;

    /**
     * 查询vims平台截图信息列表
     */
    @PreAuthorize("@ss.hasPermi('material:image:list')")
    @GetMapping("/list")
    public TableDataInfo list(VimsImageInfo vimsImageInfo,@RequestParam("toekn")String token)
    {

        startPage();
        List<VimsImageInfo> list = vimsImageInfoService.selectVimsImageInfoList(vimsImageInfo);
        return getDataTable(list);
    }

    /**
     * 导出vims平台截图信息列表
     */
    @PreAuthorize("@ss.hasPermi('material:image:export')")
    @Log(title = "vims平台截图信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(VimsImageInfo vimsImageInfo)
    {
        List<VimsImageInfo> list = vimsImageInfoService.selectVimsImageInfoList(vimsImageInfo);
        ExcelUtil<VimsImageInfo> util = new ExcelUtil<VimsImageInfo>(VimsImageInfo.class);
        return util.exportExcel(list, "vims平台截图信息数据");
    }

    /**
     * 获取vims平台截图信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('material:image:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(vimsImageInfoService.selectVimsImageInfoById(id));
    }

    /**
     * 新增vims平台截图信息
     */
    @PreAuthorize("@ss.hasPermi('material:image:add')")
    @Log(title = "vims平台截图信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VimsImageInfo vimsImageInfo)
    {
        return toAjax(vimsImageInfoService.insertVimsImageInfo(vimsImageInfo));
    }

    /**
     * 修改vims平台截图信息
     */
    @PreAuthorize("@ss.hasPermi('material:image:edit')")
    @Log(title = "vims平台截图信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VimsImageInfo vimsImageInfo)
    {
        return toAjax(vimsImageInfoService.updateVimsImageInfo(vimsImageInfo));
    }

    /**
     * 删除vims平台截图信息
     */
    @PreAuthorize("@ss.hasPermi('material:image:remove')")
    @Log(title = "vims平台截图信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(vimsImageInfoService.deleteVimsImageInfoByIds(ids));
    }

    /**
     * VIMS 保存接收的图片
     * @param images
     * @return
     */
    @CrossOrigin
    @PostMapping("/save_received_data")
    public AjaxResult saveVIMSData(@RequestBody List<ImageVo> images)
    {
        logger.debug("接受数据 {}",images);
        boolean flag = vimsFileService.saveImageFiles(images);
        if (!flag){
            return  AjaxResult.error("没收到数据");
        }
        return AjaxResult.success();
    }
    /**
     * VIMS 保存接收的图片
     * @param
     * @return
     */
    @PostMapping("/save_received_data_test")
    public AjaxResult saveVIMSDataTest()
    {
        ImageVo image = new ImageVo();
        image.setImgPath("www.baidu.com");
        image.setCaptureTime(new Date());
        image.setMissionName("test-save-data");
        image.setChannelCode("0001");
        image.setChannelName("test");
        boolean flag = vimsFileService.saveImageFile(image);
        if (!flag){
            return  AjaxResult.error("没收到数据");
        }
        return AjaxResult.success();
    }



}
